<?php
/*
	挪车卡列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'所有'),
	array('op'=>'list','title'=>'未绑定','query'=>'status=0'),
	array('op'=>'list','title'=>'已绑定','query'=>'status=1'),
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
	}
	if($_RQ['number']){
		$params['number']=intval($_RQ['number']);
		$return['params']['number']=$_RQ['number'];
	}
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['remark']){
		$params['remark like']='%'.trim($_RQ['remark']).'%';
		$return['params']['remark']=$_RQ['remark'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		
		$time_range=json_decode($time_range,true);
		
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$fields=array('id','uniacid','mid','type','number','code','salt','createtime','remark','url');
	$list=pdo_getslice('jy_move_car_cards',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			//查询用户信息
			if($item['mid']){
				$item['nickname']=pdo_getcolumn('jy_move_car_member',array('mid'=>$item['mid']),'name');
			}else{
				$item['nickname']='未绑定';
			}
			$item['card_number']=$this->card_number($item['number']);
			$item['user_num']=$this->user_number($item['number']);;
			
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'card_number','title'=>'挪车卡编号','type'=>'string'),
			array('name'=>'nickname','title'=>'所属用户','type'=>'string'),
			array('name'=>'user_num','title'=>'用户码','type'=>'string'),
			array('name'=>'remark','title'=>'场景备注','type'=>'string'),
			array('name'=>'type','title'=>'二维码类型','type'=>'radio','options'=>'types'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			array('name'=>'createtime','title'=>'生成时间','type'=>'time'),
			array('name'=>'salt','title'=>'加密盐','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'type','width'=>15,'title'=>'类型','type'=>'radio','options'=>'types'),
			array('name'=>'number','width'=>15,'title'=>'挪车卡编号','type'=>'string'),
			array('name'=>'remark','width'=>15,'title'=>'场景备注','type'=>'string'),
			array('name'=>'createtime','width'=>15,'title'=>'生成时间','type'=>'time_range'),
		),
	);
	$return['types']=array('0'=>'不限','1'=>'含参','2'=>'智能');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
	}
	if($_RQ['number']){
		$params['number']=intval($_RQ['number']);
		$return['params']['number']=$_RQ['number'];
	}
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if($_RQ['remark']){
		$params['remark like']='%'.trim($_RQ['remark']).'%';
		$return['params']['remark']=$_RQ['remark'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		
		$time_range=json_decode($time_range,true);
		
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		
	}
	$fields=array('id','uniacid','mid','type','number','code','salt','createtime','remark','url');
	$list=pdo_getall('jy_move_car_cards',$params,$fields,'','id desc');
	if($list){
		$types=array('0'=>'不限','1'=>'含参','2'=>'智能');
		foreach($list as &$item){
			//查询用户信息
			if($item['mid']){
				$item['nickname']=pdo_getcolumn('jy_move_car_member',array('mid'=>$item['mid']),'name');
			}else{
				$item['nickname']='未绑定';
			}
			$item['card_number']=$this->card_number($item['number']);
			$item['user_num']=$this->user_number($item['number']);;
			$item['type']=$types[$item['type']];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	$header=array(
		'card_number'=>'挪车卡编号',
		'nickname'=>'所属用户',
		'user_num'=>'用户码',
		'remark'=>'场景备注',
		'type'=>'二维码类型',
		'url'=>'二维码链接',
		'createtime'=>'生成时间',
	);
	cfc('tools')->export2excel($header,$list,'挪车卡列表');
}